<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增用户通道')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: s2ztree-css" />

</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-userChannel-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">商户编码：</label>
                <div class="col-sm-8">
<!--                    <input name="userId" class="form-control" type="text" required>-->
<!--                    <select name="userId"  class="form-control" th:with="type=${@sysUser.selectUserListByType('dl')}">-->
<!--                        <option value="">所有</option>-->
<!--                        <option th:each="dict : ${type}" th:text="${dict.userName}" th:value="${dict.userId}"></option>-->
<!--                    </select>-->
                    <select  name="userId" id="userId" class="form-control" multiple></select>

                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">通道类型：</label>
                <div class="col-sm-8">
                    <select name="type" id="type" class="form-control" th:with="type=${@dict.getType('channel_type')}" onchange="changeType()">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">通道编码：</label>
                <div class="col-sm-8">
                    <select name="channel" id="channel"  class="form-control" onchange="changeChannel()">
                        <option value="">所有</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">商户费率：</label>
                <div class="col-sm-8">
                    <input name="userRate" class="form-control" type="text" placeholder="万分之几,比如100就是百1" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">是否禁用：</label>
                <div class="col-sm-8">
                    <select name="disabled"  class="form-control" th:with="type=${@dict.getType('yes_or_no')}">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" hidden="hidden"  id="isv_div">
                <label class="col-sm-3 control-label is-required">服务商：</label>
                <div class="col-sm-8">
                    <select name="isvInfo"  class="form-control" th:with="type=${@isvInfo.selectTIsvInfoListByType(0)}">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.isvName}" th:value="${dict.id}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: s2ztree-js" />

    <script th:inline="javascript">
        var prefix = ctx + "business/userChannel"
        var userTreeurl = ctx + "system/user/userTreeData" ;

        var setting = {
            view : {
                dblClickExpand : false,
                expandAll: true  // 设置默认展开所有节点
            },
            data : {
                simpleData : {
                    enable : true
                }
            },
            check: {
                enable: true,
                chkStyle: "checkbox",
                chkboxType: { "Y": "s", "N": "ps" }
            },
        };
        $("#form-userChannel-add").validate({
            focusCleanup: true
        });

        getUserSelectTree();
        function getUserSelectTree() {
            //查询条件
            var params = {
                merchantType: "dl"
            };
            var config = {
                url:userTreeurl ,
                type: "post",
                dataType: "json",
                data: params,
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    // $.modal.disable();
                },
                success: function(result) {
                    $.modal.closeLoading();
                    $('select[name=userId]').select2ztree({
                        textField : 'name',
                        titleField : 'name',
                        ztree : {
                            setting : $.extend(true, {
                                treeId : 'userId'
                            }, setting),
                            zNodes : result
                        }
                    });

                }
            };
            $.ajax(config)
        }

        function changeType(){
            requrl=ctx+"business/channel/getChannel/"+$("#type").val();
            var config = {
                url:requrl ,
                type: "post",
                dataType: "json",
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    // $.modal.disable();
                },
                success: function(result) {
                    $.modal.closeLoading();
                    if (result.code == web_status.SUCCESS) {
                        $("#channel").html("");
                        $.each(result.data, function(key, val) {
                            var option1 = $("<option>").val(val.channel).text(val.channelDesc);
                            $("#channel").append(option1);
                            // form.render('select');
                        });
                    }else{
                        $.modal.alertError(result.msg);
                    }
                }
            };
            $.ajax(config)
        }

        function changeChannel() {
            var channel = $("#channel").val();
            if(channel.startsWith("isv_alipay")){
                $("#isv_div").show();
            }else{
                $("#isv_div").hide();
            }
        }

        function submitHandler() {
            var data = $("#form-userChannel-add").serializeArray();
            var userIds = $('select[name=userId]').select2ztree('val');
            data.push({"name": "userIds", "value": userIds});
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", data);
            }
        }
    </script>
</body>
</html>